package com.itheima.类加载与反射.反射.反射核心案例_使用场景;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
import java.util.Properties;

public class 类加载加反射机制案例 {
    public static void main(String[] args) throws Exception {
        //1.
        ClassLoader system=类加载加反射机制案例.class.getClassLoader();
        //ClassLoader system=ClassLoader.getSystemClassLoader();
        //2.使用转码流
        InputStream input = system.getResourceAsStream("prop.properties");
        BufferedReader br=new BufferedReader(new InputStreamReader(input));
        //3.
        Properties prop=new Properties();
        //4.
        prop.load(br);
        //5.
        String className = prop.getProperty("className");
        //6.
        String method = prop.getProperty("method");
        //7.
        Class clazz = Class.forName(className);
        Constructor con = clazz.getDeclaredConstructor();
        Object obj = con.newInstance();
        //8.
        Method md= clazz.getDeclaredMethod(method);
        md.setAccessible(true);
        //9.
        Object invoke = md.invoke(obj);
        //System.out.println(invoke);
        //10.

    }
}
